package com.topfinance.cnaps2.web.admin;

import java.util.HashMap;

import com.topfinance.cnaps2.ebo.SysUserEbo;
import com.topfinance.cnaps2.service.ISysUserManager;
import com.topfinance.cnaps2.web.data.SysUserQryForm;
import com.topfinance.frame.dao.Page;
import com.topfinance.frame.web.BaseSupport;
import com.topfinance.frame.web.PageReq;
import com.opensymphony.xwork2.ModelDriven;

/**
 * <p>
 * Description:
 * </p>
 * 
 * @author
 * @version 1.50
 *          <p>
 *          Copyright: Copyright (c) 2004 2005
 *          </p>
 *          <p>
 *          Company:
 *          </p>
 */
public final class SysUserAction extends BaseSupport implements ModelDriven<SysUserEbo> {

	private ISysUserManager sysUserManager = null;

	private SysUserQryForm sysUserQryForm = new SysUserQryForm();

	private SysUserEbo sysUserEbo = new SysUserEbo();

	public SysUserEbo getModel() {
		return sysUserEbo;
	}

	public void setSysUserManager(ISysUserManager sysUserManager) {
		this.sysUserManager = sysUserManager;
	}

	public SysUserAction() {
		super();
	}

	public String execute() {
		return list();
	}

	public String list() {
		log.debug("SysUserAction-list begin");
		PageReq pageReq = getPageReq();

		try {
			//Page page = sysUserManager.find(sysUserQryForm, pageReq);
			rtnResultMap = new HashMap();
			//rtnResultMap.put(DATA_LIST_ROOT, page.getList());
			//rtnResultMap.put(RECORDS_COUNT, page.getTotalRecs());
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("SysUserAction-list end");
		return SUCCESS;
	}

	public String create() {
		try {
			sysUserManager.save(sysUserEbo);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", "true");
			String[] args = new String[1];
			//args[0] = "" + sysUserEbo.getUserId();
			rtnResultMap.put("info", getText(CREATE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}

	public String preUpdate() {
		if (request.getParameter("id") == null) {
			rtnResultMap = new HashMap();
			String[] args = new String[1];
			args[0] = "";// you can add extra message here
			rtnResultMap.put("info", getText("expect.valid.pk.data", args));
			return SUCCESS;
		}
		try {
			String id = request.getParameter("id");
			SysUserEbo sysUserEbo = sysUserManager.get(Long.parseLong(id));
			rtnResultMap = new HashMap();
			dataList.add(sysUserEbo);
			rtnResultMap.put(EDIT_DATA_ROOT, dataList);
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}

	public String update() {
		try {
			sysUserManager.update(sysUserEbo);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", "true");
			String[] args = new String[1];
			args[0] = "";// you can add extra message here.
			rtnResultMap.put("info", getText(UPDATE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}

	public SysUserQryForm getSysUserQryForm() {
		return sysUserQryForm;
	}

	public void setSysUserQryForm(SysUserQryForm sysUserQryForm) {
		this.sysUserQryForm = sysUserQryForm;
	}

	public SysUserEbo getSysUserEbo() {
		return sysUserEbo;
	}

	public void setSysUserEbo(SysUserEbo sysUserEbo) {
		this.sysUserEbo = sysUserEbo;
	}

	// public String delete()
	// {
	// String delIds = request.getParameter("delIds");
	// try {
	// sysUserManager.delete(o)(delIds);
	// rtnResultMap = new HashMap();
	// rtnResultMap.put("success","true");
	// String [] args =new String[1];
	// args[0]= "";//you can add extra message here.
	// rtnResultMap.put("info",getText(DELETE_SUCCESS_KEY,args));
	// } catch (Exception e) {
	// handleException(e);
	// }
	// return SUCCESS;
	// }

}
